package com.iteye.trafficRecorder;

import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.TabHost;
import android.widget.Toast;

public class MainActivity extends FragmentActivity {
	
	private DatabaseHelper dbHelper;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_main);
        
        dbHelper = new DatabaseHelper(this);
        dbHelper.openDb();
        
        TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);  
        tabHost.setup();  
        
        tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator(getString(R.string.tab_regist)).setContent(R.id.tab1));
        tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator(getString(R.string.tab_setting)).setContent(R.id.tab2));
        
        openGPSSettings();
		/*
        TabWidget tabWidget = tabHost.getTabWidget();
        for (int i = 0; i < tabWidget.getChildCount(); i++) {
			tabWidget.getChildAt(i).getLayoutParams().height = 30;
			tabWidget.getChildAt(i).getLayoutParams().width = 65;
			TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);
			tv.setTextSize(15);
			tv.setTextColor(this.getResources().getColorStateList(android.R.color.white));
		}
		*/
    }
    
    private void openGPSSettings() {  
        LocationManager alm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);  
        if (alm.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {  
            Toast.makeText(this, "GPS模块正常", Toast.LENGTH_SHORT).show();  
            return;  
        }  
  
        Toast.makeText(this, "请开启GPS！", Toast.LENGTH_SHORT).show();  
        //Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);  
        //startActivityForResult(intent, 0); // 此为设置完成后返回到获取界面  
    }
    
	@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        //getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
	
	@Override
	public void onDestroy() {
		super.onDestroy();
		dbHelper.closeDb();
	}
	
	public DatabaseHelper getdb() {
		return dbHelper;
	}
}
